Skip to content

fix(api): allow setting default project when none is currently set#976

Merged
groksrc merged 1 commit into
mainfrom
fix/975-set-default-without-current
Jun 11, 2026
Merged

fix(api): allow setting default project when none is currently set#976
groksrc merged 1 commit into
mainfrom
fix/975-set-default-without-current

Conversation

@groksrc

@groksrc groksrc commented Jun 11, 2026

Copy link
Copy Markdown
Member

Closes #975

Problem

bm project default <name> failed with No default project is currently set — but setting the default is exactly the command you reach for when none is set, making a recoverable state unrecoverable from the CLI (the bootstrap/recovery case).

Repro (before the fix)

export BASIC_MEMORY_CONFIG_DIR=/tmp/bm-975-test/config BASIC_MEMORY_HOME=/tmp/bm-975-test/home
bm project add qa /tmp/bm-975-test/notes --local   # only project; no default row in DB
bm project default qa
# Error setting default project: No default project is currently set

Root cause

src/basic_memory/api/v2/routers/project_router.py set_default_project_by_id fetched the current default solely to echo it as old_project in the response, and raised 404 when there was none. That guard was marked # pragma: no cover — the no-current-default path was never tested. ProjectStatusResponse.old_project is already Optional, so the 404 served no schema requirement.

Fix

Remove the 404 guard. Build old_project=ProjectItem(...) only when a previous default exists, otherwise pass old_project=None. The rest of the handler is unchanged. No schema change needed.

A check of the rest of src/basic_memory/api/ confirmed there is no v1 router (only v2/) and the "No default project is currently set" string now appears nowhere in the tree, so there was no duplicate pattern to fix.

Test coverage

Added test_set_default_project_when_none_is_set: clears is_default so no row is default, calls the set-default endpoint, and asserts 200, old_project is None, the new project is default, and a follow-up get_default_project() returns it. All existing tests stay green. The removed # pragma: no cover guard is gone, and both branches of the new old_project construction are exercised by the existing and new tests.

Verification

  • uv run pytest tests/api/v2/test_project_router.py tests/services/test_project_service.py tests/repository/test_project_repository.py tests/cli/test_project_list_and_ls.py — 91 passed, 2 skipped
  • uv run ruff check + ruff format --check on changed files — clean
  • uv run ty check src tests test-int — All checks passed

End-to-end (the user's actual repro)

export BASIC_MEMORY_CONFIG_DIR=/tmp/bm-975-test/config BASIC_MEMORY_HOME=/tmp/bm-975-test/home
uv run bm project add qa /tmp/bm-975-test/notes --local   # Project 'qa' added successfully
uv run bm project default qa                              # Project 'qa' set as default successfully (exit 0)

bm project default qa now succeeds where it previously failed with No default project is currently set. No #974-shaped config/DB drift was encountered on this path.

🤖 Generated with Claude Code

The v2 set_default_project_by_id handler fetched the current default
solely to echo it as old_project in the response, and raised 404
"No default project is currently set" when none existed. That guard
(marked # pragma: no cover, never tested) made the bootstrap/recovery
case impossible: with no default row in the DB, `bm project default
<name>` always failed -- yet that is exactly the command you reach for
when no default is set.

ProjectStatusResponse.old_project is already Optional, so the guard
served no schema requirement. Remove it and build old_project only
when a previous default exists, else pass None.

Add a regression test that clears is_default, sets a default via the
endpoint, and asserts 200, old_project is None, the new project is
default, and a follow-up read-back returns it.

Closes #975

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Drew Cain <groksrc@gmail.com>
@groksrc groksrc marked this pull request as ready for review June 11, 2026 19:01
@groksrc groksrc merged commit be00df2 into main Jun 11, 2026
23 checks passed
@groksrc groksrc deleted the fix/975-set-default-without-current branch June 11, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot set a default project when none is currently set: v2 set-default endpoint 404s on the bootstrap/recovery case

1 participant